﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EHTSaleManager.Code.BLL;
using EHTSaleManager.Code.Entity;
using EHTSaleManager.Code.Utility;
using System.Data;
using System.IO;
using System.Net;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;


namespace EHTSaleManager.UIAdmin
{
    public partial class AdminSupport : System.Web.UI.Page
    {
        public Int32 NoteID = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["NoteID"] != null)
                {
                    try
                    {
                        NoteID = Int32.Parse(Request.QueryString["NoteID"].ToString());
                    }
                    catch (Exception ex)
                    {
                        NoteID = -1;
                    }
                }

                if (NoteID == -1)
                {
                    ViewState["action"] = HangSo.ACTION_ADD;

                }
                else
                {
                    Support theSupport = SupportsProvider.GetSupportsbyID(NoteID);

                    if (theSupport == null)
                        Response.Redirect("AdminSupports.aspx");                        
                            
                    else
                    {   
                        FCKNote.Value = theSupport.Note;
                        this.txtSkype.Text = theSupport.Skype;
                        this.txtYahoo.Text = theSupport.Yahoo;
                        this.txtGTalk.Text = theSupport.GTalk;
                        ViewState["ID"] = theSupport.ID;
                        ViewState["action"] = HangSo.ACTION_UPDATE;
                    }
                }
            }

        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminSupports.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            String action = ViewState["action"].ToString();
            
            Support theSupport = new Support();
            theSupport.Note = FCKNote.Value.ToString().Trim();
            theSupport.Skype = this.txtSkype.Text.Trim();
            theSupport.Yahoo = txtYahoo.Text.Trim();
           
            theSupport.GTalk = txtGTalk.Text.Trim();
           if(action == HangSo.ACTION_ADD)
           {
               theSupport.ID = -1;
                SupportsProvider.IUSupports(theSupport, true);
           }
           else
           {
               theSupport.ID = Int32.Parse(ViewState["ID"].ToString());
               SupportsProvider.IUSupports(theSupport, false);
           }

            Response.Redirect("AdminSupports.aspx");
        }
    }
}